<?
include("config.php");
session_start();

//this page is invisible, just tracks and cookie injects
$u      = $_REQUEST['u'];
$shop   = $_REQUEST['shopid'];
$url    = $_REQUEST['url'];
//create new object for the project
$blink = new Blink;

//is it a logged in user? if not, register the click anyway
if($u==""){
    header("Location: login.php?r=".urlencode("r.php?shopid=".$shopid."&url=".$url."&u=[userid]"));
}else{
    $t = $blink->GetToken($u);
    $row = array("token"=>$t, "userid"=>$u, "shopid"=>$shop);
    if(strpos($url,"["))
        $url=$blink->ReplaceKeys($row,$url);
    //done with replacing the values in the URL, now url encode it
    $url = urlencode($url);

//update the shop details
$res = dbQuery("insert into shopclicks (userid,shopid) values ('".$u."','".$shop."')");

//echo urldecode($url);
//now place a cookie with the user token
$_COOKIE['token'] = $t;
//echo $url;
header("Location: ".urldecode($url));
}

?>